Skip to content

fix(compiler-vapor): propagate component root through KeepAlive - #15583

Merged
edison1105 merged 4 commits into
vuejs:minorfrom
ValentinYoushkevich:fix/vapor-keepalive-root-fallthrough
Sep 23, 2026
Merged

edison1105 merged 4 commits into
vuejs:minorfrom
ValentinYoushkevich:fix/vapor-keepalive-root-fallthrough

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown
Contributor

A component whose template root is a <KeepAlive> never receives its fallthrough attributes. class, style and any other non-prop attribute are dropped, and the same binding works if the root is a <Transition> instead.

https://play.vuejs.org/#eNq1kkFv1DAQhf/Kw5cFaZNUICHIeiP1iLhwQFwwQt542rWa2NbYDVut9r+jJEuSLaL00pvHmnkz35s5iusQ8u6eRClkrNmGhEjpPqDTwXOlnG2D54RvVn8mCteN7Qg37Fus8mL52YuslulfWbtok/VumT//ngtkMbatlFNOJmpDoxNVygHyVZYh6pagU+K4RvrlUe9tY5hcCe8I7H2CjZDTHNUaaU/waU8MOberkGWj6gVK3egYt0rs/IGMEkg2NbRVYu87YrSkBIqpbIH0zDpZLIiUkzE9NP0zH+pwhLExNPqhxK7x9d0GO8+GuMTbcED0jTVgMhsEbYx1tyU+hMMGreZb64YAVxucBhfPymItHq/lf7v95BzxtKQhesZyZsf7EJCjTKJD2irxZzFTVgnnz3Tr/jkYNrtbLOUuXBuBLu/mZYgWx/IU0pxWnoGgnRmBoJltt+S6EH0MNk32TyBDN9bRF/Yhvv6+6idZ/XjzNIaxXXU8DlPjdJJFH//d+mdHHK13ohTv8vf5VcZ1/lGcfgMedWuD

The single root lookup in transform.ts treats <template> and <Transition> as transparent, but not <KeepAlive>, so the child inside is not compiled as the component root and the runtime has no root element to apply the attrs to. #15275 made <Transition> transparent for the same reason and did not carry it over.

Same shape as that fix: one more tag in the same condition. The tests cover a static child, v-if branches restored from the cache, and class merging with the child's own class.

@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: f308c836-47a9-464d-ba0f-64f6f4dc2e74

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@15583
npm i https://pkg.pr.new/@vue/compiler-core@15583
yarn add https://pkg.pr.new/@vue/compiler-core@15583.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@15583
npm i https://pkg.pr.new/@vue/compiler-dom@15583
yarn add https://pkg.pr.new/@vue/compiler-dom@15583.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@15583
npm i https://pkg.pr.new/@vue/compiler-sfc@15583
yarn add https://pkg.pr.new/@vue/compiler-sfc@15583.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@15583
npm i https://pkg.pr.new/@vue/compiler-ssr@15583
yarn add https://pkg.pr.new/@vue/compiler-ssr@15583.tgz

@vue/compiler-vapor

pnpm add https://pkg.pr.new/@vue/compiler-vapor@15583
npm i https://pkg.pr.new/@vue/compiler-vapor@15583
yarn add https://pkg.pr.new/@vue/compiler-vapor@15583.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@15583
npm i https://pkg.pr.new/@vue/reactivity@15583
yarn add https://pkg.pr.new/@vue/reactivity@15583.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@15583
npm i https://pkg.pr.new/@vue/runtime-core@15583
yarn add https://pkg.pr.new/@vue/runtime-core@15583.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@15583
npm i https://pkg.pr.new/@vue/runtime-dom@15583
yarn add https://pkg.pr.new/@vue/runtime-dom@15583.tgz

@vue/runtime-vapor

pnpm add https://pkg.pr.new/@vue/runtime-vapor@15583
npm i https://pkg.pr.new/@vue/runtime-vapor@15583
yarn add https://pkg.pr.new/@vue/runtime-vapor@15583.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@15583
npm i https://pkg.pr.new/@vue/server-renderer@15583
yarn add https://pkg.pr.new/@vue/server-renderer@15583.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@15583
npm i https://pkg.pr.new/@vue/shared@15583
yarn add https://pkg.pr.new/@vue/shared@15583.tgz

vue

pnpm add https://pkg.pr.new/vue@15583
npm i https://pkg.pr.new/vue@15583
yarn add https://pkg.pr.new/vue@15583.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@15583
npm i https://pkg.pr.new/@vue/compat@15583
yarn add https://pkg.pr.new/@vue/compat@15583.tgz

commit: c1a5d93

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 87.2 kB 30.6 kB 26.9 kB
runtime-dom.global.prod.js 116 kB 43.8 kB 39.2 kB
vue.global.prod.js 176 kB 64 kB 57 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 53.1 kB 20.7 kB 18.9 kB
createApp 61.8 kB 23.9 kB 21.7 kB
createApp + vaporInteropPlugin 124 kB (+1.38 kB) 44.7 kB (+464 B) 40.1 kB (+350 B)
createVaporApp 30.9 kB (+90 B) 11.9 kB (+30 B) 10.9 kB (+24 B)
createSSRApp 66.9 kB 25.9 kB 23.6 kB
createVaporSSRApp 37.5 kB (+396 B) 14.2 kB (+140 B) 13 kB (+121 B)
defineCustomElement 68.4 kB 25.9 kB 23.5 kB
defineVaporCustomElement 46.3 kB (+90 B) 16.8 kB (+25 B) 15.4 kB (+29 B)
overall 77.4 kB 29.4 kB 26.6 kB

@edison1105

Copy link
Copy Markdown
Member

This aligns the normal KeepAlive-root case with VDOM, but I reproduced two regressions on this head that pass on the base:

  1. Attrs leak into slot fallback components. With <KeepAlive><slot><A /></slot></KeepAlive> and <Child class="outer" />, an absent slot now causes A to inherit class="outer". VDOM does not inherit it across the slot boundary. The fallback transform rewrites the outlet into a <template>, allowing the new isSingleRoot propagation to reach the fallback component.

  2. Fallthrough listeners fire twice after interop reactivation. With a Vapor wrapper rendering <KeepAlive><VdomButton v-if="ok" /></KeepAlive> and a parent using <Child @click="spy" />, toggle ok false → true, awaiting nextTick() after each change. One click then calls spy twice; VDOM and the base call it once. The listener is now forwarded through the VDOM component’s props, while the fragment’s fallthrough hook also installs it directly on the DOM during reactivation.

@edison1105 edison1105 added scope: vapor related to vapor mode wait changes labels Sep 21, 2026
@ValentinYoushkevich

Copy link
Copy Markdown
Contributor Author

Both reproduce here, thanks. Numbers from my side.

1. Slot boundary. Confirmed: <KeepAlive><slot><A /></slot></KeepAlive> under <Child class="outer" /> renders <div id="a" class="outer">A</div> on this head against <div id="a">A</div> in VDOM, and the base has no divergence.

One thing worth knowing: the same leak is already on minor without this change, for a plain outlet root. <template><slot><A /></slot></template> puts class="outer" on the fallback in Vapor and not in VDOM. <Transition><slot>…</slot></Transition> differs too — there Vapor warns Extraneous non-props attributes where VDOM does not. So the seam is the slot boundary, and this change widens a hole rather than opening a new one. That does not make it fine, it just points at where the guard belongs.

2. Listener. Confirmed, and it depends on the child's shape. Vapor wrapper, @click on it, ok toggled false → true, one click:

vdom child base this PR VDOM
h('button'), no emits declared 1 2 1
h('button'), onClick read from attrs 1 2 1
emits: ['click'] declared 1 1 —
inheritAttrs: false 1 1 —
compiled SFC child 0 1 1

The last row is the one I would flag: on the base the listener never fires for a compiled child. The interop path drops it in one shape and, with this change, installs it twice in another.

So three lines are not enough. From what I can see the fix is a guard at the slot boundary — which also closes the pre-existing outlet case — plus not installing the fallthrough listener on the DOM when it already went through the vdom child's props.

I am happy to take it that far, with tests for all three shapes. I am equally happy to close this and leave it to you if you would rather do it in one pass with the rest of the interop work. Just say which.

@edison1105

Copy link
Copy Markdown
Member

@ValentinYoushkevich
Please go ahead with the fixes in this PR. The final behavior should match VDOM across these cases, including slot fallbacks and the different interop child shapes. Please add regression tests to verify that parity.

@ValentinYoushkevich
ValentinYoushkevich force-pushed the fix/vapor-keepalive-root-fallthrough branch from dd0a97d to 5bea80e Compare September 22, 2026 04:51
@ValentinYoushkevich

ValentinYoushkevich commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Both fixed, rebased onto current minor.

Slot boundary. One line in createFallback: clear isSingleRoot before the outlet is rewritten into a <template>, so that branch of isSingleRootChild is inert for the fallback subtree. Closes the KeepAlive case and the two pre-existing ones (plain and named outlet root) — 8 of 19 shapes diverged, now 2 — and measured the same under SSR + hydration.

It updates 7 lines of transformSlotOutlet.spec.ts.snap: the dropped bit is TemplateFlags.ROOT, which only sets $root, and every $root consumer in dom/prop.ts is component-root fallthrough.

The 2 remaining are <Transition><slot>: warning only, DOM matches, unchanged by the guard, and it reproduces when slot content is provided and the fallback never renders. Pre-existing and orthogonal, so left alone.

Listener. FallthroughResolveState has no onInteropFragment, so the descent runs past the VDOM child's bridge fragment and installs the listener again on the element the vdom renderer already patched — once per reactivation, so two toggles give three calls. That hook now folds there, as the visitor already does at a vapor component, guarded on frag.vnode so vapor fallback content still descends.

Two notes on the numbers: on the base no interop child shape gets the listener without a reactivation, so the 0-vs-1 split was a single-toggle artifact; and emits: ['click'] / inheritAttrs: false children now go from 1 call to 0, which is what an all-VDOM tree does.

Still divergent, and not this PR: a vdom child re-applying attrs.class by hand renders class="cc cc", because the interop attrs proxy hands class as a freshly built nested array and defeats mergeProps' identity check. It reproduces on minor with no KeepAlive and no v-if; the duplicate install was masking it. I'd rather fix that separately since it changes what every vdom child sees in attrs.

8 regression tests, each with the vdom equivalent as the oracle and negative controls run against the unpatched head. compiler-vapor, runtime-vapor, runtime-core, runtime-dom: 4526 passed, no failures.

ValentinYoushkevich and others added 4 commits September 23, 2026 02:37
A component whose template root is a KeepAlive never received its
fallthrough attributes: the single root lookup treats template and
Transition as transparent, but not KeepAlive, so the cached child was
not compiled as the component root and class, style and other attrs
were dropped.
@edison1105
edison1105 force-pushed the fix/vapor-keepalive-root-fallthrough branch from ecfde02 to c1a5d93 Compare September 23, 2026 09:40
@edison1105
edison1105 merged commit b6f25b0 into vuejs:minor Sep 23, 2026
15 checks passed
zhiyuanzmj added a commit to vuejs/vue-jsx-vapor that referenced this pull request Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: vapor related to vapor mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants